//
//  ByRegisterVC.m
//  Homept_ios
//
//  Created by pro on 16/9/1.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByRegisterVC.h"
#import "ByFillCodeVC.h"
#import "ByTextField.h"
#import "ByLoginViewModel.h"
@interface ByRegisterVC ()<FetchCodeDelegate>
{
    ByTextField *_field;
    ByLoginViewModel *_viewmodel;

}

@end

@implementation ByRegisterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"注册";
    [self addLeftBackBarButtonItem];
    [self createView];
    _viewmodel = [[ByLoginViewModel alloc] init];
    _viewmodel.fetchcodeDelegate = self;
    
}
#pragma mark ----创建视图
- (void)createView {
    
    CGFloat x,y,width,height;
    x = 30;
    y = 20;
    width = SCREEN_WIDTH - 2*x;
    height = LineHeight;
    _field = [[ByTextField alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _field.keyboardType = UIKeyboardTypeNumberPad;
    UIImageView *leftImg = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, LineHeight - 10, LineHeight - 10)];
    [leftImg setImage:[UIImage imageNamed:@"login_account"]];
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, LineHeight + 10, LineHeight)];
    [leftView addSubview:leftImg];
    _field.leftView = leftView;
    _field.leftViewMode = UITextFieldViewModeAlways;
    NSMutableAttributedString *paleceholderAttr = [[NSMutableAttributedString alloc] initWithString:@"请输入手机号"];
    [paleceholderAttr addAttribute:NSFontAttributeName value:FONT(16) range:NSMakeRange(0, paleceholderAttr.length)];
    [paleceholderAttr addAttribute:NSForegroundColorAttributeName value:HTB_TEXT_COLOR2 range:NSMakeRange(0, paleceholderAttr.length)];

    [_field setAttributedPlaceholder:paleceholderAttr];
    [self.view addSubview:_field];
    
    
    y = _field.bottom + 5;
    height = 1;
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    line.backgroundColor = [UIColor colorWithWhite:0.90 alpha:1];
    [self.view addSubview:line];
    
    y = line.bottom + 30;
    UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, width, 40)];
    [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
    nextBtn.backgroundColor = HTB_THEME_COLOR;
    [nextBtn addTarget:self action:@selector(nextAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextBtn];
    
}
#pragma mark ---点击事件
- (void)nextAction:(UIButton *)btn{
    
    if ([_field.text isStringNull]) {
        [ByCoreToolAlert showOnlyText:@"请输入手机号"];
        return;
    }
    if (_field.text.length != 11) {
        [ByCoreToolAlert showOnlyText:@"请输入正确手机号"];
        return;
    }
    ByFillCodeVC *vc = [[ByFillCodeVC alloc] init];
    vc.phoneNumber = _field.text;
    vc.type = @"1";
//    vc.passcode = result.data;
    [self by_normalPush:vc hasNavi:YES];
//    ByNetParamsModel *model = [[ByNetParamsModel alloc] init];
//    model.mobile = _field.text;
//    model.type = @"1";
//    [_viewmodel fetchCode:model];
    
}
#pragma mark ---相关代理
- (void)fetchCodeSuccess:(ByNetBaseResult *)result{
//    [ByCoreToolAlert showOnlyText:result.data];
    
//    ByFillCodeVC *vc = [[ByFillCodeVC alloc] init];
//    vc.phoneNumber = _field.text;
//    vc.type = @"1";
//    vc.passcode = result.data;
//    [self by_normalPush:vc hasNavi:YES];
}
- (void)fetchCodeFail:(ByNetBaseResult *)result{
    [ByCoreToolAlert showFailureWithText:result.msg];
}



@end
